/*Set operations
by Owais Lone
   SE-II
   Roll no: 25133

Variables used:
Sets: a[5],b[5]
Result set: c[10]
Set(A-B): a_b[5]
Set(B-A): b_a[5]
limits for a_b[5] & b_a[5]: lim1, lim2
switch variables: ch, ch1
flags: f
counters: i,j,k,w

*/


#include<stdio.h>
#include<conio.h>


void main()
{
int a[5],b[5],c[10],a_b[5],b_a[5],lim1,lim2,ch,ch1,w,i,j,k=0,f;

clrscr();
	printf("Enter First Set seperated by commas.(5 elements at MAX) eg 2,1,4,5,6\n");
		for(i=0;i<5;i++)
		{
		scanf("%d,",&a[i]);
		}
clrscr();
	printf("Enter Second Set seperated by commas.(5 elements at MAX) eg 2,1,4,5,6\n");
		for(i=0;i<5;i++)
		{
		scanf("%d,",&b[i]);
		}
for(w=1;w<=1;)
{

clrscr();
printf("Enter your choice\n1:Union\n2:Intersection\n3:Difference\n4:Symmetric Difference\n5:Exit\nChoice:>");
scanf("%d",&ch);
    switch(ch)
	{

	case 1:
	{
	clrscr();
	  k=0;
		for(i=0;i<5;i++)
		{
		c[i]=a[i];
		k++;
		}
		for(i=0;i<5;i++)
		{
			for(j=0;j<5;j++)
			{
			  if(b[i]==a[j])
			  {
			  f=0;
			  break;
			  }
			  else
			  f=1;
			}
			  if(f==1)
			  {
			  c[k]=b[i];
			  k++;
			  }
		}
		printf("The Union is {");
		for(i=0;i<k;i++)
		{
		printf("%d,",c[i]);
		}
		printf("\b}");
	getch();
	break;
	}
	case 2:
	{
	clrscr();
	  k=0;
		for(i=0;i<5;i++)
		{
			for(j=0;j<5;j++)
			{
			  if(a[i]==b[j])
			  {
			  f=1;
			  break;
			  }
			  else
			  f=0;
			}
			  if(f==1)
			  {
			  c[k]=b[i];
			  k++;
			  }
		}
		if(k!=0)
		{
		printf("The Intersection is {");
		for(i=0;i<k;i++)
		{
		printf("%d,",c[i]);
		}
		printf("\b}");
		}
		if(k==0)
		{
		printf("No Common Elements found...");
		}
	getch();
	break;
	}
	case 3:
	{
	clrscr();
	printf("\t\t1:>A-B\t\t2:>B-A\nChoice:>");
	scanf("%d",&ch1);
	switch(ch1)
	{
	   case 1:
	{
	clrscr();
	k=0;
	       for(i=0;i<5;i++)
	       {
			for(j=0;j<5;j++)
			{
			  if(a[i]==b[j])
			  {
			  f=0;
			  break;
			  }
			  else
			  f=1;
			}
			if(f==1)
			{
			c[k]=a[i];
			k++;
			}
	       }
	       printf("A-B={");
	       for(i=0;i<k;i++)
	       {
	       printf("%d,",c[i]);
	       }
	       printf("\b}");
	  break;
	  }
	  case 2:
	  {
	  clrscr();
	  k=0;
	       for(i=0;i<5;i++)
	       {
			for(j=0;j<5;j++)
			{
			  if(b[i]==a[j])
			  {
			  f=0;
			  break;
			  }
			  else
			  f=1;
			}
			if(f==1)
			{
			c[k]=b[i];
			k++;
			}
	       }
	       printf("B-A={");
	       for(i=0;i<k;i++)
	       {
	       printf("%d,",c[i]);
	       }
	       printf("\b}");
	  }
	}
       }
       case 4:
       {
	clrscr();
	  k=0;
	       for(i=0;i<5;i++)
	       {
			for(j=0;j<5;j++)
			{
			  if(a[i]==b[j])
			  {
			  f=0;
			  break;
			  }
			  else
			  f=1;
			}
			if(f==1)
			{
			a_b[k]=a[i];
			k++;
			}
	       }
	       lim1=k;
	   clrscr();
	  k=0;
	       for(i=0;i<5;i++)
	       {
			for(j=0;j<5;j++)
			{
			  if(b[i]==a[j])
			  {
			  f=0;
			  break;
			  }
			  else
			  f=1;
			}
			if(f==1)
			{
			b_a[k]=b[i];
			k++;
			}
	       }
	       lim2=k;
	       clrscr();
	  k=0;
		for(i=0;i<lim1;i++)
		{
		c[i]=a_b[i];
		k++;
		}
		for(i=0;i<lim2;i++)
		{
			for(j=0;j<lim1;j++)
			{
			  if(b_a[i]==a_b[j])
			  {
			  f=0;
			  break;
			  }
			  else
			  f=1;
			}
			  if(f==1)
			  {
			  c[k]=b_a[i];
			  k++;
			  }
		}
		printf("The Symmetric Difference is {");
		for(i=0;i<k;i++)
		{
		printf("%d,",c[i]);
		}
		printf("\b}");
	getch();


       }

    clrscr();
    break;
    case 5:
    w=2;
    }
}
}